<?php 
class Model_DbTable_Products_Price_Flexpricecategory extends Zend_Db_Table_Abstract {
	protected $_name = 'products_v1_flexprice_category_model';
	
	/**
	 * @author Leo
	 * @version 2014-07-07
	 * @param int $idCategory
	 * @return boolean|Ambigous <multitype:, array>
	 * get cateogory detail by ID
	 */
	public function getCategory( $idCategory){
	
		$row = $this->fetchRow("`id_category` = ". $idCategory);
		if(!$row) return false;
		return $row->toArray();
	
	}
	/**
	 * @author Leo
	 * @version 2014-07-07
	 * @param string $titleCategory
	 * @return boolean|Ambigous <multitype:, array>
	 * get cateogory detail by category name
	 */
	
	public function getCategoryByName( $titleCategory){
	
		$row = $this->fetchRow("`title_category` = '". $titleCategory."'");
		if(!$row) return false;
		return $row->toArray();
	
	}
	
	/**
	 * @author Leo
	 * @version 2014-07-07 
	 * @param string $titleCategory
	 * @param date $reviewDate
	 * @param float $percentagePrice
	 * @param float $detailPrice
	 * Add new category 
	 */
	
	public function addCategory( $titleCategory , $reviewDate, $percentagePrice, $detailPrice){
	
		$data = array(
					
				"title_category" =>  $titleCategory ,
				"review_date" =>  $reviewDate,
				"percentage_price" => $percentagePrice,
				"detail_price"=> $detailPrice
	
		);
		$this->insert($data);
	
	}
	
	/**
	 * @author Leo
	 * @version 2014-07-07 
	 * @param int $idCategory
	 * @param string $titleCategory
	 * @param date $reviewDate
	 * @param float $percentagePrice
	 * @param float $detailPrice
	 * update category detail by id
	 */
	public function updateCategory(  $idCategory ,  $titleCategory , $reviewDate, $percentagePrice, $detailPrice){
		$data = array(
					
				"title_category" =>  $titleCategory ,
				"review_date" =>  $reviewDate,
				"percentage_price" => $percentagePrice,
				"detail_price"=> $detailPrice
	
		);
			
		$this->update($data,"`id_category` = ". $idCategory);
	}
	
	/**
	 * @author Leo
	 * @version 2014-07-07  
	 * @param int $idCategory
	 * Delete category detail by id
	 */
	public function deleteCategory( $idCategory){
	
		$this->delete("`id_category` = ". $idCategory);
	
	}
	/**
	 * @author Leo
	 * @version 2014-07-07 
	 * List all
	 */
	public function listAll(){
	
		$rows =$this->fetchAll("1","id_category");
		if(!$rows) return false;
		return $rows->toArray();
	
	}
	
}

?>